package com.zhl.projectmerger;

import javafx.util.Pair;
import lombok.Data;

import java.nio.file.Path;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Data
public class ProjectMergeConfig {
    // 是否合并到旧项目
    private boolean mergeToOldProject = false;
    // 是否允许多次合并覆盖
    private boolean allowReplace = true;
    // 项目名称
    private String projectName;
    // 旧项目路径
    private Path oldProjectPath;
    // 新项目路径
    private Path newProjectPath;
    // 目标项目路径
    private Path targetProjectPath;
    // 排除的目录，相对于项目根目录的目录名，示例：target
    private Set<String> excludeDirs;
    // 排除的文件，相对于项目根目录的目录名，示例：.gitignore
    private Set<String> excludeFiles;
    // 需要合并的类名的后缀，忽略大小写
    private Set<String> classNameSuffixNeedMerge;
    // 合并失败的的文件名
    private List<Pair<String, String>> mergeFailedFileNames = new CopyOnWriteArrayList<>();
    // 如果需要处理的文件量巨大，可以开启线程池，并行处理了
    private ExecutorService executorService = Executors.newWorkStealingPool(5);

    public static ProjectMergeConfig getInstance() {
        ProjectMergeConfig config = new ProjectMergeConfig();

        // 默认排除目录
        Set<String> exclude_dirs = new HashSet<>();
        exclude_dirs.add(".git");
        exclude_dirs.add("target");
        exclude_dirs.add(".idea");
        exclude_dirs.add(".mvn");
        exclude_dirs.add(".fastRequest");
        config.setExcludeDirs(exclude_dirs);

        // 默认排除文件
        Set<String> exclude_files = new HashSet<>();
        exclude_files.add(".apt_generated");
        exclude_files.add(".classpath");
        exclude_files.add(".factorypath");
        exclude_files.add(".project");
        exclude_files.add(".settings");
        exclude_files.add(".springBeans");
        exclude_files.add(".sts4-cache");
        exclude_files.add(".iws");
        exclude_files.add(".iml");
        exclude_files.add(".ipr");
        config.setExcludeFiles(exclude_files);

        // 默认需要增量合并的类名后缀
        Set<String> classNameSuffixNeedMerge = new HashSet<>();
        classNameSuffixNeedMerge.add("Controller");
        classNameSuffixNeedMerge.add("Service");
        classNameSuffixNeedMerge.add("ServiceImpl");
        classNameSuffixNeedMerge.add("ServiceImp");
        classNameSuffixNeedMerge.add("Mapper");
        classNameSuffixNeedMerge.add("Dao");
        classNameSuffixNeedMerge.add("Repository");
        classNameSuffixNeedMerge.add("DaoImpl");
        classNameSuffixNeedMerge.add("DaoImp");
        classNameSuffixNeedMerge.add("Dto");
        config.setClassNameSuffixNeedMerge(classNameSuffixNeedMerge);

        return config;
    }
}